cap program drop mydisp
program mydisp, eclass
         matrix betass=e(b)
         matrix colnames betass = "inr"
         mat list betass
         ereturn repost b = betass, rename
 end

local append outreg, merge(r) starloc(1) var stats(b se) blankrow  merge starlevels(10 5 1) bdec(4) noau  keep(lnMW ) nolegend
local append1 outreg, merge(s) starloc(1) var stats(b se) blankrow  merge starlevels(10 5 1) bdec(4) noau   nolegend


/*=========== Dube Period =========*/
local j 1
local d 1
outreg, clear
local thresholdlist   1
foreach j of numlist `thresholdlist' {
outreg, clear
use "${data1}march_regready_1984.dta" , clear
keep if demgroup1==1
cap drop under
g  under = contpov2 < `j'
local q = `j' * 100
di "Poverty threshold `q'"
label var lnMW "INR<`j'"
local i 1
sum under  [aw=wtsupp]
local DVmean=   `r(mean)'
di `DVmean'
estimates use "${est}ster/84/MW1_`q'_dem`d'_s1_spatial_var"
  local obs : display %11.0gc `e(N)'
  local beta = _b[lnMW]
  di `beta'
  local elas:  di %5.3f `beta'/`DVmean'
  di `elas'
  outreg, store(r)  starloc(1) replace var stats(b se )  blankrow starlevels(10 5 1) bdec(4) noau keep(lnMW ) nolegend ///
  addrow("Elast", "[`elas']"\"""`obs'" ) ct("","(1)"   )

forvalues s = 2/5 {

   use "${data1}march_regready_1984.dta" , clear
  label var lnMW "INR<`j'"


 estimates use "${est}ster/84/MW1_`q'_dem`d'_s`s'_spatial_var"

  local obs : display %11.0gc `e(N)'

  local beta = _b[lnMW]
  di `beta'
  local elas:  di %5.3f `beta'/`DVmean'
  di `elas'
`append' addrow("Elast", "[`elas']"\"" "`obs'") ct("","(`s')"   )
}
******* LR *****
estimates use "${est}ster/84/MW2_`q'_dem`d'_s1_spatial_var"

  local obs : display %11.0gc `e(N)'

  lincom lnMW +lnMWL1 +lnMWL2 +lnMWL3
  local beta = `r(estimate)'
  di `beta'
  local elas:  di %5.3f `beta'/`DVmean'
  di `elas'
  lincomest lnMW +lnMWL1 +lnMWL2 +lnMWL3
  mydisp

  outreg, store(s)  starloc(1) replace var stats(b se )  blankrow starlevels(10 5 1) bdec(4) noau nolegend ///
  addrow("Elast", "[`elas']"\"","`obs'") ct("","(1)"   )

forvalues s = 2/5 {

  estimates use "${est}ster/84/MW2_`q'_dem`d'_s`s'_spatial_var"

  local obs : display %11.0gc `e(N)'
  lincom lnMW +lnMWL1 +lnMWL2 +lnMWL3
  local beta = `r(estimate)'
  di `beta'
  local elas:  di %5.3f `beta'/`DVmean'
  di `elas'
  lincomest lnMW +lnMWL1 +lnMWL2  +lnMWL3
  mydisp
  `append1' addrow("Elast", "[`elas']"\"","`obs'") ct("","(`s')"   )
}


outreg, replay append(r)
outreg, replay append(s)

outreg, replay
outreg using "${est}t6_`q'_spacial_controls", statfont( fs12 ) basefont(fs12) replay replace landscape
}


/*=============== Dube Controls ===========*/
local j 1
local d 1
outreg, clear
local thresholdlist   1
foreach j of numlist `thresholdlist' {
outreg, clear

  use "${data1}regready_cps_ipums_84.dta" , clear
  replace contpov = contpov_dube
cap drop under
g  under = contpov < `j'
local q = `j' * 100
di "Poverty threshold `q'"
label var lnMW "INR<`j'"
local i 1
sum under  [aw=asecwt]
local DVmean=   `r(mean)'
di `DVmean'
estimates use "${est}ster/84/MW1_`q'_dem`d'_s1_spatial_var_dubecont"
  local obs : display %11.0gc `e(N)'
  local beta = _b[lnMW]
  di `beta'
  local elas:  di %5.3f `beta'/`DVmean'
  di `elas'
  outreg, store(r)  starloc(1) replace var stats(b se )  blankrow starlevels(10 5 1) bdec(4) noau keep(lnMW ) nolegend ///
  addrow("Elast", "[`elas']"\"""`obs'" ) ct("","(1)"   )

forvalues s = 2/5 {

 estimates use "${est}ster/84/MW1_`q'_dem`d'_s`s'_spatial_var_dubecont"

  local obs : display %11.0gc `e(N)'

  local beta = _b[lnMW]
  di `beta'
  local elas:  di %5.3f `beta'/`DVmean'
  di `elas'
`append' addrow("Elast", "[`elas']"\"" "`obs'") ct("","(`s')"   )
}
******* LR *****
estimates use "${est}ster/84/MW2_`q'_dem`d'_s1_spatial_var_dubecont"

  local obs : display %11.0gc `e(N)'

  lincom lnMW +lnMWL1 +lnMWL2 +lnMWL3
  local beta = `r(estimate)'
  di `beta'
  local elas:  di %5.3f `beta'/`DVmean'
  di `elas'
  lincomest lnMW +lnMWL1 +lnMWL2 +lnMWL3
  mydisp

  outreg, store(s)  starloc(1) replace var stats(b se )  blankrow starlevels(10 5 1) bdec(4) noau nolegend ///
  addrow("Elast", "[`elas']"\"","`obs'") ct("","(1)"   )

forvalues s = 2/5 {

  estimates use "${est}ster/84/MW2_`q'_dem`d'_s`s'_spatial_var_dubecont"

  local obs : display %11.0gc `e(N)'
  lincom lnMW +lnMWL1 +lnMWL2 +lnMWL3
  local beta = `r(estimate)'
  di `beta'
  local elas:  di %5.3f `beta'/`DVmean'
  di `elas'
  lincomest lnMW +lnMWL1 +lnMWL2  +lnMWL3
  mydisp
  `append1' addrow("Elast", "[`elas']"\"","`obs'") ct("","(`s')"   )
}


outreg, replay append(r)
outreg, replay append(s)

outreg, replay
outreg using "${est}t6_`q'_spacial_controls_dubecont", statfont( fs12 ) basefont(fs12) replay replace landscape
}





/*=============== Our Controls ===========*/
local j 1
local d 1
outreg, clear
local thresholdlist   1
foreach j of numlist `thresholdlist' {
outreg, clear

  use "${data1}regready_cps_ipums_84.dta" , clear
  replace contpov = contpov_dube
cap drop under
g  under = contpov < `j'
local q = `j' * 100
di "Poverty threshold `q'"
label var lnMW "INR<`j'"
local i 1
sum under  [aw=asecwt]
local DVmean=   `r(mean)'
di `DVmean'
estimates use "${est}ster/84/MW1_`q'_dem`d'_s1_spatial_var_84"
  local obs : display %11.0gc `e(N)'
  local beta = _b[lnMW]
  di `beta'
  local elas:  di %5.3f `beta'/`DVmean'
  di `elas'
  outreg, store(r)  starloc(1) replace var stats(b se )  blankrow starlevels(10 5 1) bdec(4) noau keep(lnMW ) nolegend ///
  addrow("Elast", "[`elas']"\"""`obs'" ) ct("","(1)"   )

forvalues s = 2/5 {

 estimates use "${est}ster/84/MW1_`q'_dem`d'_s`s'_spatial_var_84"

  local obs : display %11.0gc `e(N)'

  local beta = _b[lnMW]
  di `beta'
  local elas:  di %5.3f `beta'/`DVmean'
  di `elas'
`append' addrow("Elast", "[`elas']"\"" "`obs'") ct("","(`s')"   )
}
******* LR *****
estimates use "${est}ster/84/MW2_`q'_dem`d'_s1_spatial_var_84"

  local obs : display %11.0gc `e(N)'

  lincom lnMW +lnMWL1 +lnMWL2 +lnMWL3
  local beta = `r(estimate)'
  di `beta'
  local elas:  di %5.3f `beta'/`DVmean'
  di `elas'
  lincomest lnMW +lnMWL1 +lnMWL2 +lnMWL3
  mydisp

  outreg, store(s)  starloc(1) replace var stats(b se )  blankrow starlevels(10 5 1) bdec(4) noau nolegend ///
  addrow("Elast", "[`elas']"\"","`obs'") ct("","(1)"   )

forvalues s = 2/5 {

  estimates use "${est}ster/84/MW2_`q'_dem`d'_s`s'_spatial_var_84"

  local obs : display %11.0gc `e(N)'
  lincom lnMW +lnMWL1 +lnMWL2 +lnMWL3
  local beta = `r(estimate)'
  di `beta'
  local elas:  di %5.3f `beta'/`DVmean'
  di `elas'
  lincomest lnMW +lnMWL1 +lnMWL2  +lnMWL3
  mydisp
  `append1' addrow("Elast", "[`elas']"\"","`obs'") ct("","(`s')"   )
}


outreg, replay append(r)
outreg, replay append(s)

outreg, replay
outreg using "${est}t6_`q'_spacial_controls_ourcont", statfont( fs12 ) basefont(fs12) replay replace landscape
}

